//
//  ServiceAgreementView.m
//  CedarFinancePH
//
//  Created by lshenrong on 2018/3/29.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "ServiceAgreementView.h"
#import "CedarButton.h"

@interface ServiceAgreementView()

@property (nonatomic,copy) NSString *title;
@property (nonatomic,copy) NSString *agreement;

@end

@implementation ServiceAgreementView

- (instancetype)initWithTitle:(NSString *)title agreement:(NSString *)content{
    if (self = [super init]) {
        self.title = title;
        self.agreement = content;
        [self initUI];
    }
    return self;
}


- (void)initUI{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *highlightImage = [UIImage imageNamed:@"Agree"];
    [btn setImage:highlightImage forState:UIControlStateNormal];
    self.isSelectedStatus = YES;
    [btn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(1);
        make.top.mas_equalTo(1);
        make.bottom.mas_equalTo(-1);
        make.width.mas_offset(40);
    }];
    
    UILabel *label = [[UILabel alloc]init];
    MACRO_UILabel_Configure(label, self.title, kGrayColor, 12)
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(btn.mas_right).mas_offset(2);
        make.centerY.mas_equalTo(self);
    }];
    
    CedarButton *agreementBtn = [CedarButton buttonWithTextNoStytle:self.agreement];
    [agreementBtn PFCGStyleTextColor:kOrangeColor fontSize:12];
    [self addSubview:agreementBtn];
    //[agreementBtn setTitleColor:kMasterColor forState:UIControlStateNormal];
    [agreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label.mas_right).mas_offset(2);
        make.centerY.mas_equalTo(self);
        make.height.mas_offset(40);
    }];
}

- (void)clickButton:(UIButton *)button{
    self.isSelectedStatus = !self.isSelectedStatus;
    if (self.isSelectedStatus ) {
        UIImage *normalImage = [UIImage imageNamed:@"Agree"];
        [button setImage:normalImage forState:UIControlStateNormal];
    }else{
        UIImage *highlightImage = [UIImage imageNamed:@"NoAgree"];
        [button setImage:highlightImage forState:UIControlStateNormal];
    }
    if (self.agreementBlock) {
        self.agreementBlock(self.isSelectedStatus);
    }
}


@end
